using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;


[CreateAssetMenu(fileName = "Condition01-几回合执行一次", menuName = "Skill/Condition/Condition01-几回合执行一次", order = 1)]
public class Condition01 : ConditionBase
{
    public int maxCount;
    
    private Dictionary<Pair,int> RecordingChessDic = new Dictionary<Pair,int>();
    public override bool Evaluate(Pair pair,GameEvent e)
    {
        RecordingChessDic.TryAdd(pair, 0);
        
        if (e is not TurnChangeEvent turnChangeEvent) return false;
        if (turnChangeEvent.TurnSide != pair.Chess.GetChessSide()) return false;
        RecordingChessDic[pair]++;
        if (RecordingChessDic[pair] < maxCount) return false;
        RecordingChessDic[pair] -= maxCount;
        return true;
    }

    public override void RemoveDictionary(Pair pair)
    {
        RecordingChessDic.Remove(pair);
    }

    private void OnDestroy()
    {
        RecordingChessDic.Clear();
    }
}
